package com.caipu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.caipu.entity.Dish;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper extends BaseMapper<Dish> {
    
    @Select("SELECT d.* FROM dish d " +
            "LEFT JOIN dish_tag dt ON d.id = dt.dish_id " +
            "WHERE d.deleted = 0 " +
            "AND (#{categoryId} IS NULL OR d.category_id = #{categoryId}) " +
            "AND (#{tagIds} IS NULL OR dt.tag_id IN (${tagIds})) " +
            "AND (#{keyword} IS NULL OR d.name LIKE CONCAT('%', #{keyword}, '%')) " +
            "GROUP BY d.id")
    List<Dish> searchDishes(@Param("categoryId") Long categoryId, 
                           @Param("tagIds") String tagIds, 
                           @Param("keyword") String keyword);
    
    @Select("${sql}")
    List<Dish> selectByCustomSql(@Param("sql") String sql);
}